///公用的界面跳转方法
import router from '../router'
import store from '../repo/store/store'

export function generateRouterPath(path) {

  let hsId = store.getters.hsId;
  let loginType = store.getters.loginType;

  return `${path}/${loginType}/${hsId}`
}

export function push(path) {
  let location = generateRouterPath(path);
  return router.push(location)
}

export function replace(path) {
  let location = generateRouterPath(path);
  return router.replace(location)
}

export function pushName(name) {
  let hsId = store.getters.hsId;
  let loginType = store.state.auth.loginType;
  let params = {loginType, hsId};
  return router.push({name: name, params: params})

}

export function replaceName(name) {
  let hsId = store.getters.hsId;
  let loginType = store.state.auth.loginType;
  let planId = store.getters.getPlanId;
  let params = {loginType, hsId, planId};
  return router.replace({name: name, params: params})

}

export function replaceNameWithParam(path) {
  let hsId = store.getters.hsId;
  let loginType = store.state.auth.loginType;
  return router.replace(`${path}/${loginType}/${hsId}`)

}

export function simpleVertifyId(card) {
  // 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X
  let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  return (reg.test(card) !== false);
}

export const getPath = path => `${path}/:loginType/:hsId`;
